// 帖子相关类型定义
import type { BaseEntity, User, Tag, FileInfo, Comment, Like, Bookmark, Category } from './index'

// 帖子类型枚举
export enum PostType {
  DISCUSSION = 'discussion',
  QUESTION = 'question',
  SHARE = 'share',
  ANNOUNCEMENT = 'announcement',
  TASK = 'task',
  OTHER = 'other'
}

// 帖子状态枚举
export enum PostStatus {
  DRAFT = 'draft',
  PENDING = 'pending',
  PUBLISHED = 'published',
  ARCHIVED = 'archived',
  DELETED = 'deleted',
  LOCKED = 'locked'
}

// 帖子可见性枚举
export enum PostVisibility {
  PUBLIC = 'public',
  PRIVATE = 'private',
  FRIENDS_ONLY = 'friends_only',
  GROUP_ONLY = 'group_only'
}

// 帖子接口
export interface Post extends BaseEntity {
  title: string
  content: string
  type: PostType | string
  status: PostStatus | string
  visibility: PostVisibility | string
  authorId: string | number
  author?: User
  category?: Category
  tags?: Tag[]
  viewCount: number
  replyCount: number
  likeCount: number
  bookmarkCount: number
  shareCount: number
  isPinned?: boolean
  isHot?: boolean
  isRecommended?: boolean
  groupId?: string | number
  courseId?: string | number
  resourceId?: string | number
  questionId?: string | number
  parentId?: string | number
  parentPost?: Post
  lastReplyAt?: string
  lastReplyUserId?: string | number
  lastReplyUser?: User
  attachments?: FileInfo[]
  coverImage?: string
  metadata?: Record<string, any>
  comments?: Comment[]
  likes?: Like[]
  bookmarks?: Bookmark[]
  relatedPosts?: Post[]
}

// 帖子搜索参数接口
export interface PostSearchParams {
  keyword?: string
  type?: PostType | string
  status?: PostStatus | string
  visibility?: PostVisibility | string
  authorId?: string | number
  categoryId?: string | number
  tagIds?: string[]
  groupId?: string | number
  courseId?: string | number
  resourceId?: string | number
  questionId?: string | number
  parentId?: string | number
  isPinned?: boolean
  isHot?: boolean
  isRecommended?: boolean
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
  startDate?: string
  endDate?: string
  page?: number
  pageSize?: number
  includePrivate?: boolean
}

// 创建帖子接口
export interface CreatePost {
  title: string
  content: string
  type: PostType | string
  visibility: PostVisibility | string
  categoryId?: string | number
  tagIds?: string[]
  groupId?: string | number
  courseId?: string | number
  resourceId?: string | number
  questionId?: string | number
  parentId?: string | number
  attachments?: FileInfo[]
  coverImage?: string
  metadata?: Record<string, any>
}

// 更新帖子接口
export interface UpdatePost {
  title?: string
  content?: string
  type?: PostType | string
  status?: PostStatus | string
  visibility?: PostVisibility | string
  categoryId?: string | number
  tagIds?: string[]
  groupId?: string | number
  courseId?: string | number
  resourceId?: string | number
  questionId?: string | number
  parentId?: string | number
  isPinned?: boolean
  isHot?: boolean
  isRecommended?: boolean
  attachments?: FileInfo[]
  coverImage?: string
  metadata?: Record<string, any>
}

// 帖子统计接口
export interface PostStats {
  posts: number
  views: number
  replies: number
  likes: number
  bookmarks: number
  shares: number
  averageReplies: number
  engagementRate: number
  postedPerDay: {
    date: string
    count: number
  }[]
}

// 帖子分类统计接口
export interface PostCategoryStats {
  categoryId: string | number
  categoryName: string
  postCount: number
  viewCount: number
  replyCount: number
  likeCount: number
}

// 帖子标签统计接口
export interface PostTagStats {
  tagId: string | number
  tagName: string
  postCount: number
  viewCount: number
  replyCount: number
  likeCount: number
}

// 置顶帖子接口
export interface PinnedPost {
  id: string | number
  postId: string | number
  post?: Post
  pinnedByUserId: string | number
  pinnedByUser?: User
  pinnedAt: string
  reason?: string
  expiresAt?: string
}

// 热门帖子接口
export interface HotPost {
  id: string | number
  postId: string | number
  post?: Post
  score: number
  period: 'daily' | 'weekly' | 'monthly'
  rank: number
  change: number
}

// 推荐帖子接口
export interface RecommendedPost {
  id: string | number
  postId: string | number
  post?: Post
  recommendedByUserId: string | number
  recommendedByUser?: User
  recommendedUserId: string | number
  recommendedUser?: User
  reason?: string
  score?: number
  recommendedAt: string
  isRead?: boolean
  readAt?: string
}

// 帖子报告接口
export interface PostReport {
  id: string | number
  postId: string | number
  post?: Post
  reporterId: string | number
  reporter?: User
  reason: string
  description?: string
  status: 'pending' | 'processing' | 'resolved' | 'dismissed'
  createdAt: string
  resolvedAt?: string
  resolvedByUserId?: string | number
  resolvedByUser?: User
}

// 帖子收藏接口
export interface PostCollection {
  id: string | number
  userId: string | number
  user?: User
  postId: string | number
  post?: Post
  collectionDate: string
  notes?: string
  folderId?: string | number
  folder?: PostFolder
}

// 帖子文件夹接口
export interface PostFolder {
  id: string | number
  userId: string | number
  user?: User
  name: string
  description?: string
  parentId?: string | number
  parent?: PostFolder
  postCount: number
  folderCount: number
  createdAt: string
  updatedAt: string
}

// 帖子分享接口
export interface PostShare {
  id: string | number
  postId: string | number
  post?: Post
  sharerId: string | number
  sharer?: User
  receiverId?: string | number
  receiver?: User
  platform: string
  shareText?: string
  shareDate: string
  isSuccessful?: boolean
}

// 帖子活动记录接口
export interface PostActivityLog {
  id: string | number
  postId: string | number
  post?: Post
  userId: string | number
  user?: User
  action: 'view' | 'like' | 'bookmark' | 'share' | 'reply' | 'edit' | 'delete'
  timestamp: string
  details?: string
}

// 帖子评论接口
export interface PostComment extends Comment {
  postId: string | number
  post?: Post
}

// 帖子点赞接口
export interface PostLike extends Like {
  postId: string | number
  post?: Post
}

// 帖子书签接口
export interface PostBookmark extends Bookmark {
  postId: string | number
  post?: Post
}

// 帖子分析接口
export interface PostAnalytics {
  postId: string | number
  post?: Post
  totalViews: number
  uniqueViews: number
  totalReplies: number
  totalLikes: number
  totalBookmarks: number
  totalShares: number
  engagementRate: number
  conversionRate: number
  viewDuration?: number
  dropOffPoints?: {
    position: number
    percentage: number
  }[]
  demographics?: {
    ageGroups: Record<string, number>
    genders: Record<string, number>
    countries: Record<string, number>
  }
  performanceTrend: {
    date: string
    views: number
    replies: number
    likes: number
    bookmarks: number
  }[]
}